package com.ztgf.shopping.api.client.shop;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.common.utils.StrUtils;
import com.ztgf.shopping.models.bo.shop.ShopSalesAreaSaveBO;
import com.ztgf.shopping.models.vo.shop.ShopSalesAreaVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import com.ztgf.shopping.models.service.shop.IShopSalesAreaService;
import com.ztgf.shopping.models.bo.shop.ShopSalesAreaBO;
import com.ztgf.shopping.models.dto.shop.ShopSalesAreaDTO;

import java.util.Arrays;
import java.util.List;

/**
 * 店铺可售区域表控制器
 *
 * @author zhanghualang
 * @Date 2020-05-27 15:21:49
 */

@RestController
@RequestMapping("/api/shopSalesArea")
@Slf4j
@Api(value = "ShopSalesAreaApiController",tags = "店铺可售区域表Api接口")
public class ShopSalesAreaApiController {

    @DubboReference
    private IShopSalesAreaService shopSalesAreaService;

    @PostMapping("/update")
    @ApiOperation(value = "修改店铺可售区域表",notes = "修改店铺可售区域表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "shopId",value = "shopId",required = true,paramType = "query", dataType = "Long"),
            @ApiImplicitParam(name = "ids",value = "ids:以逗号隔开",required = true,paramType = "query", dataType = "String")
    })
    public Result updateArea(@RequestParam("shopId") Long shopId ,@RequestParam("ids") String ids){
        if(null == shopId || StrUtils.isEmpty(ids)){
            return new Result(CodeEnum.FAIL_100002 );
        }
        String[] arr = ids.split(",");
        boolean flag = shopSalesAreaService.updateArea(shopId, ids);

        if (flag){
            return new Result<>();
        }else{
            return new Result<>(CodeEnum.FAIL);
        }

    }

    @PostMapping("/get")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<ShopSalesAreaDTO> get(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }

        ShopSalesAreaDTO dto = shopSalesAreaService.selectById(id);

        return new Result<>(dto);
    }

    @ApiOperation(value = "店铺可售区域表列表",notes = "店铺可售区域表列表")
    @PostMapping("/queryPageList")
    public Result<List<ShopSalesAreaVO>> queryPageList(ShopSalesAreaBO bo){

        List<ShopSalesAreaVO> shopSalesAreaVOS = shopSalesAreaService.queryList(bo);

        return new Result<>(shopSalesAreaVOS);
    }

    @ApiOperation(value = "店铺所有可售区域表列表",notes = "店铺所有可售区域表列表")
    @PostMapping("/queryAllPageList")
    public Result<List<ShopSalesAreaVO>> queryAllPageList(ShopSalesAreaBO bo){

        List<ShopSalesAreaVO> shopSalesAreaVOS = shopSalesAreaService.queryAllList(bo);

        return new Result<>(shopSalesAreaVOS);
    }
}
